/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts.Exercise.NewExercise;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.util.MessageResources;

/**
 *
 * @author Tarde
 */
public class NewExerciseForm extends org.apache.struts.action.ActionForm {
    
    private Integer idejercicio;
    private String titulo;
    private String descripcion;
    private Integer tema;

        
    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public Integer getTema() {
        return tema;
    }

    public void setTema(Integer tema) {
        this.tema = tema;
    }

    public String getTitulo() {
        return titulo;
    }

    public void setTitulo(String titulo) {
        this.titulo = titulo;
    }
    
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {


        ActionErrors errors = new ActionErrors();

        /**
         * ***************************************
         */
        //Recupero el fichero de recursos
        MessageResources m;
        m = (MessageResources) request.getAttribute(Globals.MESSAGES_KEY);

        //Idioma actual
        java.util.Locale idioma = (java.util.Locale) request.getSession().getAttribute(Globals.LOCALE_KEY);
        /**
         * **************************************
         */
        if ((titulo == null)||(titulo.length()<=0)) {
            errors.add("titulo", new ActionMessage("error.empty", m.getMessage(idioma, "error.titulo")));
        }
        if ((descripcion == null)||(descripcion.length()<=0)) {
            errors.add("descripcion", new ActionMessage("error.empty", m.getMessage(idioma, "error.descripcion")));
        }

        return errors;
    }

    public Integer getIdejercicio() {
        return idejercicio;
    }

    public void setIdejercicio(Integer idejercicio) {
        this.idejercicio = idejercicio;
    }
}
